package com.javafx.everythingdemo.caches;

import com.javafx.everythingdemo.config.SQLiteConfig;

import javax.swing.filechooser.FileSystemView;
import java.io.File;
import java.util.*;

public class Index {
    public static void sst() {

////        获取所有盘符
//        List<String> list=getAllDisk();
//        for (String str : list) {
//            System.out.println(str);
//            File file = new File(str);
//            getAllFilePath(file);//遍历盘符中的所有文件
//        }

        List<Map<String,String>> list =new ArrayList<>();
        Map<String,String> filesmap=new HashMap<>();//文件
        Map<String,String> foldermap=new HashMap<>();//文件夹
        list.add(filesmap);
        list.add(foldermap);

//        File file = new File("D:\\面试\\面试");

            getAllFilePath(new File("D:\\面试"),list);


        SQLiteConfig.insert(list);

    }

    /**
     *  获取该电脑所有盘符
     * @return list
     */
    public static List<String> getAllDisk(){
        File[] roots = File.listRoots();
        FileSystemView sys = FileSystemView.getFileSystemView();
        List<String> list=new ArrayList<String>();
        for (File root : roots) {
            if (!sys.getSystemTypeDescription(root).equals("本地磁盘")) {
                continue;
            }
            list.add(root.getPath());
//            System.out.println(roots[i].getPath());// 磁盘路径
        }
//        System.out.println(list);
        return list;
    }
//    遍历盘符中所有文件
    public static void getAllFilePath(File dir,List<Map<String,String>> list){

        File[] files=dir.listFiles();
        String split="\\\\";
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory()) {
//                    System.out.println(files[i].getPath());
                    String[] sp = file.getPath().split(split);
                    System.out.println(Arrays.toString(sp));
                    list.get(1).put(sp[sp.length - 1], file.getPath());
                    //这里面用了递归的算法  
                    getAllFilePath(file, list);
                } else {
//                    System.out.println(files[i].getPath());//将文件名打印
                    String[] sp = file.getPath().split(split);
                    list.get(0).put(sp[sp.length - 1], file.getPath());
                    System.out.println(Arrays.toString(sp));
                }
            }
        }
    }
}
